﻿using System.Numerics;
using System;
namespace Primer
{
    public interface ITracker
    {
        Action<BigInteger> Add { get; }
        bool Run { get; }
        void Send(BigInteger v, int method, object[] args);
    }

    internal class Tracker : ITracker
    {
        public Tracker(Action<BigInteger> add, Action<BigInteger> commit, Action<BigInteger> rollback)
        {
            Add = add;
            Commit = commit;
            Rollback = rollback;
        }

        public Action<BigInteger> Add { get; private set; }
        public Action<BigInteger> Commit { get; private set; }
        public Action<BigInteger> Rollback { get; private set; }

        public bool Run
        {
            get { return true; }
        }

        public void Send(BigInteger id, int method, object[] args)
        {
            switch (method)
            {
                case 0:
                    Console.WriteLine("[{0} idle]", id);
                    return;
                case 1:
                    Console.WriteLine("{0,5}: {1}", id, args[0]);
                    Add(id);
                    return;
            }
        }
    }
}
